/*
 * Copyright (C) 2013 TopCoder Inc., All Rights Reserved.
 */
package cn.itcast.heima;

/**
 * @author TCSASSEMBLER
 * @version 1.0 ()
 * @since 1.0
 */
public class TraditionalThreadSynchronized {

	public static void main(String[] args) {
		new TraditionalThreadSynchronized().init();
	}
	
	private void init() {
		final Outputer outputer = new Outputer();
		new Thread(
				new  Runnable() {
					
					@Override
					public void run() {
						while(true) {
							try {
								Thread.sleep(500);
							} catch (InterruptedException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							outputer.output("niudongze");
						}
					}
				}
		).start();
		
		new Thread(
				new  Runnable() {
					
					@Override
					public void run() {
						while(true) {
							try {
								Thread.sleep(500);
							} catch (InterruptedException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							outputer.output("zhangxiaoxiang");
						}
					}
				}
		).start();
	}
	
	
	class Outputer {
		/*public void output(String name) {
			int length = name.length();
			synchronized (this.getClass().getName()){
				for(int i = 0; i < length; i++) {
					System.out.print(name.charAt(i));
				}
				System.out.println();
			}
		}*/
		
		public synchronized void output(String name) {
			int length = name.length();
			synchronized (this.getClass().getName()){
				for(int i = 0; i < length; i++) {
					System.out.print(name.charAt(i));
				}
				System.out.println();
			}
		}
	}
	
}


